package models

import (
	"time"
)

type Resource struct {
	Id     int
	Uuid   string `orm:"unique;index;size(32)"` //唯一uuid
	Flag   int
	Public bool   `orm:"default(0)"`
	Fname  string `orm:"size(256)"`
	Key    string `orm:"size(512)"` //是否公开
	Bucket string `orm:"size(64)"`
	Mime   string `orm:"size(64)"` //文件类型
	Size   int    //大小
	Height int
	Width  int
	Hash   string `orm:"size(64)"`

	Link string `orm:"-"`

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	UsedBy string `orm:size(32);`
	UserId string `orm:size(32); index`
	//	Tags      []*Tag      `orm:"rel(m2m)"`
	//	Comments  []*Comment  `orm:"rel(m2m)"`
	//	Upvotes   []*Upvote   `orm:"rel(m2m)"`
	//	Binders   []*Binder   `orm:"reverse(many)"`
	//	Downloads []*Download `orm:"reverse(many)"`
}

func (p *Auth) Resource() [][]string {
	return [][]string{
		[]string{"Flag", "UserId"},
	}
}

type Matter struct {
	Id   int
	Uuid string `orm:"unique;index;size(32)"` //唯一uuid

	Flag int

	Title string `orm:"size(1024)"`
	Desc  string `orm:"size(4096)"`

	Score int //积分

	Deleted bool

	Link   string `orm:"size(4096)"` //展示图片地址
	Size   int    //大小
	Height int
	Width  int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)" ` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)" `     //创建更新设置为当前时间
	DeleteAt time.Time `orm:"type(datetime)" `              //创建更新设置为当前时间

	PicId  string `orm:size(32) ` //psd展示源文件uuid
	ShowId string `orm:size(32) ` //psd展示源文件uuid
	PsdId  string `orm:size(32) ` //psd展示源文件uuid
	UserId string `orm:size(32); index `
	//	Tags      []*Tag      `orm:"rel(m2m)"`
	//	Comments  []*Comment  `orm:"rel(m2m)"`
	//	Upvotes   []*Upvote   `orm:"rel(m2m)"`
	//	Binders   []*Binder   `orm:"reverse(many)"`
	//	Downloads []*Download `orm:"reverse(many)"`
	User         *User     `orm:"-"`
	IsPsd        bool      `orm:"-"`
	PicResource  *Resource `orm:"-"`
	ShowResource *Resource `orm:"-"`
	PsdResource  *Resource `orm:"-"`
	Category     *Category `orm:"-"`
	Tags         []*Tag    `orm:"-"`
}

type Binder struct {
	Id      int
	Uuid    string `orm:"unique;index;size(32)"` //唯一uuid
	Title   string `orm:"index;size(1024)"`      //唯一uuid
	Desc    string `orm:"size(4096)"`
	IsPub   bool   //是否公开
	Deleted bool   //是否公开

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间
	DeleteAt time.Time `orm:"type(datetime)"`              //创建更新设置为当前时间

	UserId string `orm:size(32); index`

	User     *User     `orm:"-"`
	Category *Category `orm:"-"`
	Tags     []*Tag    `orm:"-"`

	//	User      *User       `orm:"rel(fk)"`
	//	Tags      []*Tag      `orm:"rel(m2m)"`
	//	Resources []*Resource `orm:"rel(m2m)"`
	//	Comments  []*Comment  `orm:"rel(m2m)"`
	//	Upvotes   []*Upvote   `orm:"rel(m2m)"`
}

type BindersMap struct {
	Id int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	BinderId string `orm:size(32); index`
	Flag     int
	RelId    string `orm:size(32); index`
}

func (p *BindersMap) TableUnique() [][]string {
	return [][]string{
		[]string{"BinderId", "Flag", "RelId"},
	}
}

func (p *BindersMap) TableIndex() [][]string {
	return [][]string{
		[]string{"Flag", "RelId"},
	}
}

type Class struct {
	Id      int
	Name    string `orm:"unique;index;size(32)" `
	Comment string `orm:"size(4096)" `

	CreateAt time.Time `orm:"auto_now_add;type(datetime)" ` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)" `     //创建更新设置为当前时间
}

type Tag struct {
	Id   int
	Name string `orm:"size(32);index"`

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	//	Resources []*Resource `orm:"reverse(many)"`
	//	Binders   []*Binder   `orm:"reverse(many)"`
	ClassId int `orm:"index"`

	Count int //此字段只是用于 orm框架自动填充

}

type TagsMap struct {
	Id int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	TagId int `orm:"index"`
	Flag  int
	RelId string `orm:"size(32)"`
}

func (p *TagsMap) TableUnique() [][]string {
	return [][]string{
		[]string{"TagId", "Flag", "RelId"},
	}
}

func (p *TagsMap) TableIndex() [][]string {
	return [][]string{
		[]string{"Flag", "RelId"},
	}
}

type Category struct {
	Id       int
	ParentId int
	Name     string `orm:"size(32)" `

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	Count int //此字段只是用于 orm框架自动填充
}

type CategorysMap struct {
	Id int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	CategoryId int `orm:"index"`
	Flag       int
	RelId      string `orm:"size(32)"`
}

func (p *CategorysMap) TableUnique() [][]string {
	return [][]string{
		[]string{"CategoryId", "Flag", "RelId"},
	}
}

func (p *CategorysMap) TableIndex() [][]string {
	return [][]string{
		[]string{"Flag", "RelId"},
	}
}

type DownloadRecord struct { //下载记录
	Id int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	Link string `orm:size(4096)` //下载的链接地址

	UserId   string `orm:size(32); index`
	MatterId string `orm:size(32); index`

	//User     *User     `orm:"rel(fk)"`
	//Resource *Resource `orm:"rel(fk)"`
}

type ConvertRecord struct { //兑换记录
	Id int

	Const int

	CreateAt time.Time `orm:"auto_now_add;type(datetime)"` //创建时设置为当前时间
	UpdateAt time.Time `orm:"auto_now;type(datetime)"`     //创建更新设置为当前时间

	UserId   string `orm:size(32); index`
	MatterId string `orm:size(32); index`

	//User     *User     `orm:"rel(fk)"`
	//Resource *Resource `orm:"rel(fk)"`
}

func (p *ConvertRecord) TableUnique() [][]string {
	return [][]string{
		[]string{"UserId", "MatterId"},
	}
}
